<?php
//header('Content-type: application/json');
class Admin_Order_Controller extends Base_Controller {

    public function action_index()
    {        
        return View::make('admin/order');
    }


    public function action_getdata()
    {
        $factorPgData = DB::table('member_order')
                ->left_join('member','member.id','=','member_order.mid')
                ->select(array('member_order.*','member.nickname'))
                ->where('member_order.dele','=',1)
                ->paginate(10);
     

        foreach($factorPgData->results as $k =>$v){
            $factorPgData->results[$k]['creattime']=date('Y-m-d H:i:s',$v['creattime']);
            if($v['status']==-1){
                $factorPgData->results[$k]['status']='未支付';
            }else{
                 $factorPgData->results[$k]['status']='以支付';
            }
        };

        $res = array(
            'code'=>0,
            'msg'=>'',
            'count'=>$factorPgData->total,
            'data'=>$factorPgData->results,
            );

        return Response::json($res); //把数据转化成json返回
    }



    public function action_dele()
    {
        $id = Input::get('id');
        $dele = -1;
        $str = DB::table('member_order')->where('id','=',$id)->update(array('dele'=>$dele));
        if($str){
            $data = array(
                'code'=>'200',
                'msg'=>'删除成功'
                );
        }else{
            $data = array(
                'code'=>'400',
                'msg'=>'删除失败'
                );
        }
        return json_encode($data);

    }



    public function action_detail()
    {

        $id = Input::get('id');
        $str = DB::table('member_order')
                ->left_join('member','member.id','=','member_order.mid')
                ->select(array('member_order.*','member.nickname'))
                ->where('member_order.id','=',$id)
                ->first();
        return View::make('admin/orderdetail',array('str'=>$str));

    }














   

}







